/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package docview;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.io.File;
import java.sql.SQLException;
import javax.swing.JTextArea;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import tableprocessor.SessionFactoryUtil;
/**
 *
 * @author gleb
 */
public class SplashAndCheckerDocView  extends Frame 
{

    private JTextArea tarea = new JTextArea();
    public SplashAndCheckerDocView()
    {
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        this.setUndecorated(true);
        int w = (int) (dim.getWidth() / 3);
        int h = (int) (dim.getHeight() / 3);
        int x = (int) (dim.getWidth()/2 - w/2);
        int y = (int) (dim.getHeight()/2 - h/2);
        this.setLayout(new GridLayout(1,1));
        this.setBounds(x, y, w, h);
        tarea.setEditable(false);
        tarea.setBackground(this.getBackground());
        this.setVisible(true);
        add(tarea);


    }
    public  boolean start()
    {
        boolean rez = true;
        tarea.append("Инициализация...\n");
        tarea.append("Чтение файла конфигурации Hibernate...");
        Configuration conf = new Configuration();
        try
        {
            conf.configure(new File("config/hibernate.cfg.xml"));
            tarea.append("OK\n");
        }
        catch (Exception e)
        {
            tarea.append("FAIL\n");
            rez = false;
        }
        tarea.append("Проверка соединения с сервером...");
        try
        {
            conf.buildSessionFactory().openSession().connection().isValid(0);
            tarea.append("OK\n");
            tarea.append("Запуск приложения...\n");
            this.setVisible(false);
        }
        catch(Exception e)
        {
            e.printStackTrace();
            tarea.append("FAIL\n");
            rez = false;
        }
        return rez;
    }
}
